package com.huilian.netty.handler;

import com.huilian.iotbox.data.common.RedisKey;
import com.huilian.netty.model.CIMSession;
import com.huilian.netty.model.SocketMessage;
import com.huilian.netty.repository.SessionRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.concurrent.TimeUnit;

/**
 * @author 谢洛涛
 * @date 2024/5/28 18:18
 */
@Component
public class BindHandler implements CIMRequestHandler {
    private static final Logger LOGGER = LoggerFactory.getLogger(BindHandler.class);
    @Autowired
    private SessionRepository sessionRepository;
    @Override
    public void process(CIMSession session, SocketMessage message) {
        if(message.getUsername()!=null){
            session.setusername(message.getUsername());
            sessionRepository.save(session);
        }
        LOGGER.info("登录时存缓存：{}", message.getUsername());
    }
}
